package com.example.modules.common;

import com.example.modules.dictionary.DictionaryService;
import com.example.modules.user.UserDetailsVO;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/common")
@AllArgsConstructor
public class CommonController {
    DictionaryService dictionaryService;

    /**
     * 获取初始化数据，包括个人信息、数据字典
     */
    @GetMapping("/initial")
    @PreAuthorize("hasAuthority('showPersonalDetail')")
    public Map<String, Object> getInitialConfig(@AuthenticationPrincipal UserDetailsVO userInfo) {
        Map<String, Object> result = new HashMap<>();
        result.put("user", userInfo);
        result.put("dictionary", dictionaryService.resolveDictionary());
        return result;
    }
}
